Passed
Pull Request — master (#182)
by Mathieu
04:33
created

GetProjectsAction.index   A

Complexity

Conditions 1

Size

Total Lines 9
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 9
dl 0
loc 9
rs 9.95
c 0
b 0
f 0
1
import {Controller, Inject, UseGuards, Get, Query} from '@nestjs/common';
2
import {AuthGuard} from '@nestjs/passport';
3
import {ApiTags, ApiBearerAuth, ApiOperation} from '@nestjs/swagger';
4
import {ProjectView} from 'src/Application/Project/View/ProjectView';
5
import {IQueryBus} from 'src/Application/IQueryBus';
6
import {GetProjectsQuery} from 'src/Application/Project/Query/GetProjectsQuery';
7
import {FiltersDTO} from '../DTO/FiltersDTO';
8
import {Roles} from 'src/Infrastructure/HumanResource/User/Decorator/Roles';
9
import {UserRole} from 'src/Domain/HumanResource/User/User.entity';
10
import {RolesGuard} from 'src/Infrastructure/HumanResource/User/Security/RolesGuard';
11
import {Pagination} from 'src/Application/Common/Pagination';
12
13
@Controller('projects')
14
@ApiTags('Project')
15
@ApiBearerAuth()
16
@UseGuards(AuthGuard('bearer'), RolesGuard)
17
export class GetProjectsAction {
18
  constructor(
19
    @Inject('IQueryBus')
20
    private readonly queryBus: IQueryBus
21
  ) {}
22
23
  @Get()
24
  @Roles(UserRole.COOPERATOR, UserRole.EMPLOYEE)
25
  @ApiOperation({summary: 'Get all projects ordered by customer'})
26
  public async index(
27
    @Query() filters: FiltersDTO
28
  ): Promise<Pagination<ProjectView>> {
29
    return await this.queryBus.execute(
30
      new GetProjectsQuery(Number(filters.page), filters.customerId)
31
    );
32
  }
33
}
34